package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.dto.req.paid.PaidAddReqDto;
import com.yixin.hospital.entity.vo.CurVisitAmountVo;
import com.yixin.hospital.service.PaidService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/paid")
@Api(value = "缴费", tags = "缴费")
@Slf4j
public class PaidController {

    @Autowired
    private PaidService paidService;

    @GetMapping("/cur-visit/amount")
    @ApiOperation(value = "获取本次诊断支付金额")
    public ApiResult<CurVisitAmountVo> getCurVisitAmount(@RequestParam("guidanceCode") String guidanceCode, @RequestParam("patientId") String patientId) {
        return paidService.getCurVisitAmount(guidanceCode, patientId);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增缴费记录，暂不连接支付，添加即认定为支付")
    @Transactional(rollbackFor = Exception.class)
    public ApiResult<CurVisitAmountVo> addPaid(@Valid @RequestBody PaidAddReqDto paidAddReqDto, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return paidService.add(paidAddReqDto, userName);
    }

}
